package cn.com.zero.common.auth.security.handler;

import cn.com.zero.common.auth.constant.SecurityConstants;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author xiongxj
 * @version 1.0.0
 * @Description 自定义的认证成功后的处理类
 * @createTime 2023/3/23 16:57
 */
@Component
public class LoginAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        request.setAttribute("authenticationException", exception);
        request.getRequestDispatcher(SecurityConstants.SECURITY_CONTROLLER_PATH + "/loginAuthenticationFailureHandler").forward(request, response);
    }

}
